package day2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

//新版try-catch 实现文件复制
public class TestCopy2 {
    public static void main(String[] args) {
        //try(){}catch{}
        //可以将需要关闭资源的内容放入()编写  他会帮你自动关闭
        try (FileInputStream fis = new FileInputStream("d://a//b//d.txt");
             FileOutputStream fos = new FileOutputStream("d://a//Newd.txt");) {
            long start = System.currentTimeMillis();
            byte[] bs = new byte[1024];
            int len = 0;
            while ((len = fis.read(bs)) != -1) {
                fos.write(bs, 0, len);
            }
            long end = System.currentTimeMillis();
            System.out.println((end - start) + "ms");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
